﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using ArgusControls.MessageBoxButtonsUIControls;

namespace ArgusControls
{
	public partial class MessageBox : ChildWindow
	{
		Action<MessageBoxResults> closeAction;
		MessageBoxButtonsUI mbbUI;

		private MessageBox(string Text, string Caption, MessageBoxButtonsUI mbbUI, Action<MessageBoxResults> action)
		{
			InitializeComponent();
			this.tbText.Text = Text;
			this.Title = Caption;
			this.placeHolderMessageBoxButtons.Children.Add(mbbUI);
			this.closeAction = action;
			this.mbbUI = mbbUI;
			mbbUI.MessageBoxResultChanged += mbbUI_MessageBoxResultChanged;
		}

		void mbbUI_MessageBoxResultChanged(object sender, RoutedPropertyChangedEventArgs<MessageBoxResults> e)
		{
			this.Close();
		}

		protected override void OnClosed(EventArgs e)
		{
			base.OnClosed(e);
			this.closeAction(this.mbbUI.MessageBoxResult);
		}

		public static void Show(string Text, string Caption, MessageBoxButtons Buttons, Size MinWindowSize, Action<MessageBoxResults> action)
		{
			MessageBoxButtonsUI mbbUI = new MessageBoxButtonsUIOK();
			if (Buttons == MessageBoxButtons.OKCancel)
				mbbUI = new MessageBoxButtonsUIOKCancel();
			else if (Buttons == MessageBoxButtons.YesNo)
				mbbUI = new MessageBoxButtonsUIYesNo();

			MessageBox mb = new MessageBox(Text, Caption, mbbUI,action);
			if (MinWindowSize.IsEmpty == false)
			{
				mb.MinWidth = MinWindowSize.Width;
				mb.MinHeight = MinWindowSize.Height;
			}
			mb.Show();
		}

		public static void Show(string Text, string Caption, MessageBoxButtons Buttons, Action<MessageBoxResults> action)
		{
			MessageBox.Show(Text, Caption, Buttons, Size.Empty, action);
		}

		public static void Show(string Text, Action<MessageBoxResults> action)
		{
			MessageBox.Show(Text, string.Empty, MessageBoxButtons.OK, action);
		}
	}
}

